/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Longitud.java
 *
 * Created on 12/05/2011, 07:59:42 PM
 */

package proyecto;

/**
 *
 * @author home
 */
public class Longitud extends javax.swing.JFrame {

    /** Creates new form Longitud */
    public Longitud() {
        initComponents();
        buttonGroup1.add(mm1);
        buttonGroup1.add(cm1);
        buttonGroup1.add(m1);
        buttonGroup1.add(km1);
        buttonGroup1.add(mi1);
        buttonGroup2.add(mm2);
        buttonGroup2.add(cm2);
        buttonGroup2.add(m2);
        buttonGroup2.add(km2);
        buttonGroup2.add(mi2);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        n = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        resu = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        mi1 = new javax.swing.JRadioButton();
        cm1 = new javax.swing.JRadioButton();
        m2 = new javax.swing.JRadioButton();
        km2 = new javax.swing.JRadioButton();
        m1 = new javax.swing.JRadioButton();
        cm2 = new javax.swing.JRadioButton();
        mi2 = new javax.swing.JRadioButton();
        km1 = new javax.swing.JRadioButton();
        mm2 = new javax.swing.JRadioButton();
        mm1 = new javax.swing.JRadioButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 0, 255));
        jLabel1.setText("Longitud:");

        jLabel2.setText("Ingresar:");

        jLabel4.setText("Resultado:");

        jLabel3.setText("Convertir a:");

        mi1.setText("Mi");

        cm1.setText("Cm");

        m2.setText("M");

        km2.setText("Km");

        m1.setText("M");

        cm2.setText("Cm");

        mi2.setText("Mi");

        km1.setText("Km");

        mm2.setText("Mm");

        mm1.setText("Mm");

        jButton1.setText("Ok");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        jButton2.setText("Limpiar");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel1)
                .addContainerGap(288, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cm1)
                                    .addComponent(m1)
                                    .addComponent(km1)
                                    .addComponent(mi1)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(resu, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
                                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(mm2)
                                    .addComponent(cm2)
                                    .addComponent(m2)
                                    .addComponent(km2)
                                    .addComponent(mi2))
                                .addGap(84, 84, 84))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(mm1)
                                .addContainerGap())))
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
                        .addComponent(n, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(120, 120, 120))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(n, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(mm1)
                    .addComponent(mm2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cm1)
                    .addComponent(cm2))
                .addGap(2, 2, 2)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(m1)
                    .addComponent(m2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(km1)
                    .addComponent(km2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(mi1)
                    .addComponent(mi2))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(resu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
        // TODO add your handling code here:
        resu.setText("");
        n.setText("");
    }//GEN-LAST:event_jButton2MouseClicked

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        // TODO add your handling code here:
    double num=Double.parseDouble(n.getText());
    double res;
    if (mm1.isSelected()&&mm2.isSelected()){
    resu.setText(String.valueOf(num));
    }
    if  (mm1.isSelected()&&cm2.isSelected()){
    res=num/10;
    resu.setText(String.valueOf(res));
    }
    if  (mm1.isSelected()&&m2.isSelected()){
    res=num/1000;
    resu.setText(String.valueOf(res));
    }
    if (mm1.isSelected()&&km2.isSelected()){
    res=num/1000000;
    resu.setText(String.valueOf(res));
    }
    if (mm1.isSelected()&&mi2.isSelected()){
    res=num/1609344;
    resu.setText(String.valueOf(res));
    }
    if (cm1.isSelected()&&mm2.isSelected()){
    res=num*10;
    resu.setText(String.valueOf(res));
    }
    if (cm1.isSelected()&&cm2.isSelected()){
    resu.setText(String.valueOf(num));
    }
    if (cm1.isSelected()&&m2.isSelected()){
    res=num/100;
    resu.setText(String.valueOf(res));
    }
    if (cm1.isSelected()&&km2.isSelected()){
    res=num/100000;
    resu.setText(String.valueOf(res));
    }
    if (cm1.isSelected()&&mi2.isSelected()){
    res=num/160934.4;
    resu.setText(String.valueOf(res));
    }
    if (m1.isSelected()&&mm2.isSelected()){
    res=num*1000;
    resu.setText(String.valueOf(res));
    }
    if (m1.isSelected()&&cm2.isSelected()){
    res=num*100;
    resu.setText(String.valueOf(res));
    }
    if (m1.isSelected()&&m2.isSelected()){
    resu.setText(String.valueOf(num));
    }
    if (m1.isSelected()&&km2.isSelected()){
    res=num/1000;
    resu.setText(String.valueOf(res));
    }
    if (m1.isSelected()&&mi2.isSelected()){
    res=num/1609.344;
    resu.setText(String.valueOf(res));
    }
    if (km1.isSelected()&&mm2.isSelected()){
    res=num*1000000;
    resu.setText(String.valueOf(res));
    }
    if (km1.isSelected()&&cm2.isSelected()){
    res=num*100000;
    resu.setText(String.valueOf(res));
    }
    if (km1.isSelected()&&m2.isSelected()){
    res=num*1000;
    resu.setText(String.valueOf(res));
    }
    if (km1.isSelected()&&km2.isSelected()){
    resu.setText(String.valueOf(num));
    }
    if (km1.isSelected()&&mi2.isSelected()){
    res=num*1.609344;
    resu.setText(String.valueOf(res));
    }
    if (mi1.isSelected()&&mm2.isSelected()){
    res=(num*10000000)*1.609344;
    resu.setText(String.valueOf(res));
    }
    if (mi1.isSelected()&&cm2.isSelected()){
    res=(num*1000000)*1.609344;
    resu.setText(String.valueOf(res));
    }
    if (mi1.isSelected()&&m2.isSelected()){
    res=(num*1000)*1.609344;
    resu.setText(String.valueOf(res));
    }
    if (mi1.isSelected()&&km2.isSelected()){
    res=num*1.609344;
    resu.setText(String.valueOf(res));
    }
    if (mi1.isSelected()&&mi2.isSelected()){
    resu.setText(String.valueOf(num));
    }
    
    }//GEN-LAST:event_jButton1MouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Longitud().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JRadioButton cm1;
    private javax.swing.JRadioButton cm2;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JRadioButton km1;
    private javax.swing.JRadioButton km2;
    private javax.swing.JRadioButton m1;
    private javax.swing.JRadioButton m2;
    private javax.swing.JRadioButton mi1;
    private javax.swing.JRadioButton mi2;
    private javax.swing.JRadioButton mm1;
    private javax.swing.JRadioButton mm2;
    private javax.swing.JTextField n;
    private javax.swing.JTextField resu;
    // End of variables declaration//GEN-END:variables

}
